package com.hr.reactive.threading;

import com.hr.reactive.common.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;

/**
 * @author Administrator
 */
public class Lec02PublishOn {
    private static final Logger log = LoggerFactory.getLogger(Lec02PublishOn.class);

    public static void main(String[] args) {
        var flux = Flux.create(sink -> {
                    for (int i = 0; i < 3; i++) {
                        log.info("genering:{}", i);
                        sink.next(i);
                    }
                    sink.complete();
                });
        flux.publishOn(Schedulers.parallel())
                .doOnNext(v->log.info("values:{}",v))
                .doFirst(()->log.info("first 1"))
                .publishOn(Schedulers.boundedElastic())
                .doFirst(()->log.info("first 2"))
                .subscribe(Utils.subscriber());




        Utils.sleepSeconds(3000);
    }
    //Schedulers.immediate
    //不想改变程序调度
    private static void some(Schedulers schedulers){

    }
}
